import logging
from datetime import timedelta

from redis import Redis


class Config:
    DEBUG = True
    # 连接mysql数据
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/xjnews"
    # 设置不跟踪修改 因为浪费资源
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 定义redis数据库的主机地址，和端口号
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    # 配置session
    SESSION_TYPE = 'redis'  # session的储存类型为redis
    SESSION_REDIS = Redis(REDIS_HOST, REDIS_PORT)  # session储存数据库redis的连接
    SESSION_USE_SIGNER = True  # redis是否加密
    SECRET_KEY = 'd3Ugu67durozZ+htU6QvdurvjGSBghZIgSJANiSAMtE3NxgO/JzWWQ=='
    PERMANENT_SESSION_LIFETIME = timedelta(days=7)


# 开发环境
class DevelepConfig(Config):
    DEBUG = True
    LOG_LEVEL = logging.DEBUG  # 设置日志级别


# 生产环境
class ProductConfig(Config):
    DEBUG = False
    LOG_LEVEL = logging.ERROR



# 定义字典配置
config_dict = {
    "DEV": DevelepConfig,
    "PRO": ProductConfig
}
